<%@page language="java" contentType="text/html; charset=utf-8"%>
<%@include file="/tagDeclare.jsp"%>
<%@include file="/headDeclare.jsp"%>
<html>
<head>
	<style type="text/css"> 
	  fieldset,legend,form,table,tr,td,textarea{margin:0;padding:0}
	  form label {font-weight:bold;}
	  table{margin:10px 10px};
	  td{line-height: 40px;}
	  input[type="text"]{width:250px;}
	  input[type="password"]{width:250px;}
	  input[type="textarea"]{width:250px;}
	</style>

	<script type="text/javascript">
	 var model = 'top';
	 var num = Math.random();
	 var dialog = frameElement.dialog; //调用页面的dialog对象(ligerui对象)
	  $(document).ready(function(){
			$("#name").focus();
			
			//异步提交表单
		     var options = {dataType: 'json', beforeSubmit: beforeSubmit, success: process};
		     $("#topForm").submit(function(){
		         $(this).ajaxSubmit(options);
		          return false;
		     });   

		     setTimeout(function(){
		    	 num = Math.random();
		    	//文件上传组件
			     $("#file_upload").uploadify({   
	                  'height'        : 27,    
	    	          'width'         : 80,     
	    	          'buttonText'    : '添加附件',   
	    	          'queueID': 'fileQueue', 
	    	          'removeCompleted': false,         //上传完毕上传列表是否去除 
	    	          'fileSizeLimit': '20MB',          //上传文件大小设置 单位可以是B、KB、MB、GB 
	                  'swf'           : 'js/uploadify/uploadify.swf',   
	    	          'uploader'      : '<%=basePath%>web/upload.do;jsessionid=<%=request.getSession().getId()%>',   
	    	          'auto'          : true,   
	    	          'formData'      : {'model':model,'jsid':num},  
	    	          'fileTypeExts'  : '*.jpg;*.png;*.gif',   
	    	          'multi'			: false, 
	    	          'onUploadStart' : function(file) {   
	  	                	$("#file_upload").uploadify("settings");   
	  	           	  },   
	    	          'onUploadSuccess':function(file, data, response){ 
						  var json=eval("("+data+")"); //转换为json对象
	   	        		  if(json.code == 0){
		  	        		  $('#' + file.id).find('.data').html('上传成功');
		  	        		  $("#url").val(json.msg);
		  	        	  }else{
		  	        		  $('#' + file.id).find('.data').html(json.msg);
		  	        	  }
	    	           },
	    	           'onUploadComplete':function(file){   
	    	           }  
			      });
		     },5);

		     
 	         
	  });
	  
	//提交前验证
	   function beforeSubmit() {
		     if(isEmpty($("#name").val())) { 
		    	 $.ligerDialog.alert("图片名称不能为空！");
		    	 return false; 
		    	}
		     return true;
	   }
	
	   function process(responseJson) {
	     if(responseJson.code == 0) {
	    	 $.ligerDialog.error(responseJson.message);
	         return;
	     }
	     window.parent.topForm.submit();
	     dialog.close();
	   }  
	</script>
</head>
<body>
  <div >
      <form id="topForm" name="topForm" method="post" action="web/top/insert.do">
        <table cellpadding="10" cellspacing="10">
			<tr>
			    <td><label for="address">主题：</label></td>
				<td>
				   <input type="text" name="name" id="name" />
				</td>
			</tr>
			<tr>
				<td><label for="status">图片路径：</label></td>
				<td><input type="text" name="url" id="url" readonly="readonly" />
				<input type="file" name="uploadify" id="file_upload" style="float: left;" />
					<label id="fileQueue" style="float: left;"  ></label></td>
			</tr>
			<tr>
				<td><label for="memo" >说明:</label></td>
				<td>
					<input type="text" name="memo" id="memo"  />
				</td>
			</tr>
        </table>
      </form>
    </div>
</body>
</html>